package com.sxc.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/session02")
public class Session02 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取Session域对象
        HttpSession session = req.getSession();
        // 设置域对象
        session.setAttribute("username", "zhangsan");
        session.setAttribute("pwd", "123456");
        //移除域对象
        session.removeAttribute("pwd");
        //获取域对象
        String username = (String) session.getAttribute("username");

    }
}
